module pieces
! pieces for Tic-Tac-Toe
    implicit none
    private

    public piece_module_initialize, piece_module_finalize
    public piece, as_string, new, operator(==)

    type piece
        private
        character:: mark = " "
    end type piece

    interface new
        module procedure piece_new
    end interface

    interface as_string
        module procedure piece_as_string
    end interface

    interface operator(==)
        module procedure piece_equals
    end interface

contains

    subroutine piece_module_initialize ()
    end subroutine piece_module_initialize

    subroutine piece_module_finalize ()
    end subroutine piece_module_finalize

    subroutine piece_new(p, mark)
    character, intent(in):: mark
    type(piece), intent(out):: p
    p%mark = mark
    end subroutine piece_new

    elemental function piece_as_string(p)
    character piece_as_string
    type(piece), intent(in):: p
    piece_as_string = p%mark
    end function piece_as_string

    elemental function piece_equals(p1, p2)
    type(piece), intent(in):: p1, p2
    logical piece_equals
    piece_equals = p1%mark == p2%mark
    end function piece_equals


end module pieces